package serviceImpl;

import dao.ITheatreDao;
import models.Theatre;

import java.util.List;

/**
 * Created by 国彬 on 2016/7/3.
 */
public class TheatreDaoImpl implements ITheatreDao {


    /**
     * 分页查询影院，page第几页，length一页长度
     * @param city
     * @param page
     * @param length
     * @return
     */
    @Override
    public List findTheatresByCity(String city,int page,int length,String area) {
        if(area.equals("全部区域")){
            return Theatre.find("city=? order by score desc",city).fetch(page,length);
        }else{
            return Theatre.find("city=? and area=? order by score desc",city,area).fetch(page,length);
        }


    }

    @Override
    public List findTheatresByCityWithKeyWord(String city, int page, int length, String area, String keyWord) {
        if(area.equals("全部区域")){
            return Theatre.find("city=? and name like ? order by score desc",city,"%"+keyWord+"%").fetch(page, length);
        }else{
            return Theatre.find("city=? and area=? and name like ? order by score desc",city,area,"%"+keyWord+"%").fetch(page,length);
        }
    }

    @Override
    public Theatre findDetailById(String id) {
        return Theatre.find("id=?",id).first();
    }
}
